Skip to content

Rework TestEnv and Implement Client::get_prune_height#42

Open
luisschwab wants to merge 2 commits intobitcoindevkit:masterfrom
luisschwab:feat/client-get-prune-height
Open

Rework TestEnv and Implement Client::get_prune_height#42
luisschwab wants to merge 2 commits intobitcoindevkit:masterfrom
luisschwab:feat/client-get-prune-height

Conversation

@luisschwab
Copy link
Copy Markdown
Member

Closes #40

Changelog

- Rework the `TestEnv` to accept custom config for the `Node`
- Expose `corepc_node::Client` in the `TestEnv`

- Implement `Client::get_prune_height`

@luisschwab luisschwab requested a review from tvpeter April 5, 2026 22:07
@luisschwab luisschwab self-assigned this Apr 5, 2026
@luisschwab luisschwab added the enhancement New feature or request label Apr 5, 2026
Also exposes a`corepc_node::Client` in the `TestEnv`.
@luisschwab luisschwab force-pushed the feat/client-get-prune-height branch from 7d3798a to 7b26c34 Compare April 6, 2026 02:01
Copy link
Copy Markdown
Collaborator

@tvpeter tvpeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @luisschwab, I left a few comments.

Implement `Client::get_prune_height`, calling
`getblockchaininfo` under the hood, and returns:
  - `None`, if `bitcoind` is not pruned,
  - `Some(u32)` with the prune height, if `bitcoind` is pruned.
@luisschwab luisschwab force-pushed the feat/client-get-prune-height branch from 7b26c34 to b4536a9 Compare April 6, 2026 14:39
@luisschwab luisschwab requested a review from tvpeter April 6, 2026 14:39
@luisschwab
Copy link
Copy Markdown
Member Author

@tvpeter addressed your reviews. I'd hold off on merging this one until #39 is merged.

@tvpeter
Copy link
Copy Markdown
Collaborator

tvpeter commented Apr 6, 2026

@tvpeter addressed your reviews. I'd hold off on merging this one until #39 is merged.

The test_get_prune_height is failing at my end, and I have been trying to figure out why. Is it passing at your end?

@luisschwab
Copy link
Copy Markdown
Member Author

Can you share the error? CI and local testing is passing for me.

@tvpeter
Copy link
Copy Markdown
Collaborator

tvpeter commented Apr 6, 2026

Can you share the error? CI and local testing is passing for me.

error

@luisschwab
Copy link
Copy Markdown
Member Author

This looks like a race condition happening on your local bitcoind. Run it again with RUST_BACKTRACE=full. Just copy the terminal output instead of a screenshot this time.

@luisschwab
Copy link
Copy Markdown
Member Author

Try adding a timeout after the prune_blockchain call to confirm it's a race condition:

#[test]
fn test_get_prune_height() {
    // Spawn an unpruned node.
    let env_unpruned = TestEnv::new();

    // Assert that `getblockchaininfo.pruned` is `None`.
    let unpruned_res = env_unpruned.client.get_prune_height().unwrap();
    assert_eq!(unpruned_res, None);

    // Spawn a node with manual pruning enabled.
    let mut node_config = Conf::default();
    node_config.args.push("-prune=1");
    node_config.args.push("-fastprune");
    let env_pruned = TestEnv::new_with_config(&node_config);

    // Mine 1000 blocks.
    let block_count = 1000;
    let _hashes = env_pruned.mine_blocks(block_count as usize, None);

    // Assert that `getblockchaininfo.pruned` is `Some(0)`.
    let pruned_res = env_pruned.client.get_prune_height().unwrap();
    assert_eq!(pruned_res, Some(0));

    // Prune the last 2 blocks.
    let _ = env_pruned.corepc_client.prune_blockchain(block_count - 2);
+   std::thread::sleep(std::time::Duration::from_secs(2));

    // Assert that `getblockchaininfo.prunedheight` is > 0.
    // Note: it's not possible to assert on a specific block height since Bitcoin Core
    // prunes at the block file level (`blkXXXX.dat`), and not at block height level.
    let pruned_res = env_pruned.client.get_prune_height().unwrap();
    assert!(pruned_res > Some(0));
}

@tvpeter
Copy link
Copy Markdown
Collaborator

tvpeter commented Apr 6, 2026

Try adding a timeout after the prune_blockchain call to confirm it's a race condition:

 bdk-bitcoind-client [b4536a9] ⚡  RUST_BACKTRACE=full cargo test --package bdk-bitcoind-client --test test_rpc_client -- test_get_prune_height --exact --nocapture
   Compiling bdk-bitcoind-client v0.1.0 (/Users/vihigatyonum/OSS/bdk-bitcoind-client)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.99s
     Running tests/test_rpc_client.rs (target/debug/deps/test_rpc_client-03a920a3b375e92b)

running 1 test
test test_get_prune_height has been running for over 60 seconds

thread 'test_get_prune_height' (3258923) panicked at tests/test_rpc_client.rs:342:5:
assertion failed: pruned_res > Some(0)
stack backtrace:
   0:        0x100b267c0 - std::backtrace_rs::backtrace::libunwind::trace::h890246ace2f92943
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
   1:        0x100b267c0 - std::backtrace_rs::backtrace::trace_unsynchronized::h11f38ae193fb7a81
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
   2:        0x100b267c0 - std::sys::backtrace::_print_fmt::h4b60af7dd9328e8e
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/sys/backtrace.rs:66:9
   3:        0x100b267c0 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h2808c764b780ef77
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/sys/backtrace.rs:39:26
   4:        0x100b34d64 - core::fmt::rt::Argument::fmt::hcb261d347bc11ae5
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/fmt/rt.rs:173:76
   5:        0x100b34d64 - core::fmt::write::h164e2e78980a3344
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/fmt/mod.rs:1469:25
   6:        0x100aff064 - std::io::default_write_fmt::ha9d9e8690d3c78f2
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/io/mod.rs:639:11
   7:        0x100aff064 - std::io::Write::write_fmt::hc5b2a4d160c11c86
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/io/mod.rs:1954:13
   8:        0x100b08538 - std::sys::backtrace::BacktraceLock::print::h765d16e49e83c7b3
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/sys/backtrace.rs:42:9
   9:        0x100b0b9a0 - std::panicking::default_hook::{{closure}}::hf5d7ef6cefa10586
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:301:27
  10:        0x100b0b854 - std::panicking::default_hook::h8781bd6c5c54e4cc
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:328:9
  11:        0x100b0c0e0 - std::panicking::panic_with_hook::h93c775fc227522dd
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:834:13
  12:        0x100b0bda0 - std::panicking::panic_handler::{{closure}}::h8561e58c9391724a
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:700:13
  13:        0x100b08644 - std::sys::backtrace::__rust_end_short_backtrace::h55629ed76aaa9d26
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/sys/backtrace.rs:174:18
  14:        0x100af7890 - __rustc[d9b87f19e823c0ef]::rust_begin_unwind
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:698:5
  15:        0x100b4937c - core::panicking::panic_fmt::hfe9cfd57c06d80d9
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:80:14
  16:        0x100b4935c - core::panicking::panic::h4a3c64c65dc98033
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:150:5
  17:        0x1009485c4 - test_rpc_client::test_get_prune_height::he19bcf87becb357f
                               at /Users/vihigatyonum/OSS/bdk-bitcoind-client/tests/test_rpc_client.rs:342:5
  18:        0x1009472c8 - test_rpc_client::test_get_prune_height::{{closure}}::h9f822711f8be8993
                               at /Users/vihigatyonum/OSS/bdk-bitcoind-client/tests/test_rpc_client.rs:312:27
  19:        0x10094a408 - core::ops::function::FnOnce::call_once::hd42ded2cd65b9ac0
                               at /Users/vihigatyonum/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
  20:        0x100967cd4 - core::ops::function::FnOnce::call_once::h346a8e93af649499
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/ops/function.rs:250:5
  21:        0x100967cd4 - test::__rust_begin_short_backtrace::h0d6c6ada726cc7de
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/test/src/lib.rs:663:18
  22:        0x1009774e4 - test::run_test_in_process::{{closure}}::h00add03dc7986ec9
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/test/src/lib.rs:686:74
  23:        0x1009774e4 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h94d3c071c5a9ea81
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panic/unwind_safe.rs:274:9
  24:        0x1009774e4 - std::panicking::catch_unwind::do_call::h4ecaf85895286111
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:590:40
  25:        0x1009774e4 - std::panicking::catch_unwind::he25df76aff1a19fc
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:553:19
  26:        0x1009774e4 - std::panic::catch_unwind::h01ab4eec19193aeb
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panic.rs:359:14
  27:        0x1009774e4 - test::run_test_in_process::h3ab7c4a13adb5507
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/test/src/lib.rs:686:27
  28:        0x1009774e4 - test::run_test::{{closure}}::hfff72f3e31ffa110
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/test/src/lib.rs:607:43
  29:        0x100957c30 - test::run_test::{{closure}}::h3d49dc3760a1af33
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/test/src/lib.rs:637:41
  30:        0x100957c30 - std::sys::backtrace::__rust_begin_short_backtrace::hdc9d3c3b7ec657ef
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/sys/backtrace.rs:158:18
  31:        0x10095ab40 - std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}::h6c728ed14a8c3159
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/thread/mod.rs:562:17
  32:        0x10095ab40 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h8ce297b53608e2bc
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panic/unwind_safe.rs:274:9
  33:        0x10095ab40 - std::panicking::catch_unwind::do_call::h65240674da2098a0
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:590:40
  34:        0x10095ab40 - std::panicking::catch_unwind::h71f7e84dcc4abdb1
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:553:19
  35:        0x10095ab40 - std::panic::catch_unwind::h37217e8eedf6933d
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panic.rs:359:14
  36:        0x10095ab40 - std::thread::Builder::spawn_unchecked_::{{closure}}::h4ee5400741716276
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/thread/mod.rs:560:30
  37:        0x10095ab40 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h2ee972076698d3d2
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/ops/function.rs:250:5
  38:        0x100b05b24 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1f71a7d9fb4fcf2e
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/alloc/src/boxed.rs:2005:9
  39:        0x100b05b24 - std::sys::thread::unix::Thread::new::thread_start::h98270432b6aefc44
                               at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/sys/thread/unix.rs:126:17
  40:        0x19082bc08 - __pthread_cond_wait
test test_get_prune_height ... FAILED

failures:

failures:
    test_get_prune_height

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 18 filtered out; finished in 64.22s

error: test failed, to rerun pass `-p bdk-bitcoind-client --test test_rpc_client`
☁  bdk-bitcoind-client [b4536a9] ⚡  

@luisschwab
Copy link
Copy Markdown
Member Author

Did you set BITCOIND_EXE or are you downloading it?

@tvpeter
Copy link
Copy Markdown
Collaborator

tvpeter commented Apr 6, 2026

Did you set BITCOIND_EXE or are you downloading it?

I have set it to point to my bitcoind path in the terminal. Let add to my shell profile and retry

@luisschwab
Copy link
Copy Markdown
Member Author

luisschwab commented Apr 6, 2026

Try unsetting BITCOIND_EXE and let corepc_node download the binary.

@tvpeter
Copy link
Copy Markdown
Collaborator

tvpeter commented Apr 6, 2026

Try unsetting BITCOIND_EXE and let corepc_node download the binary.

I have done that, and it's still the same output.

This is clogging this PR conversation, so let's wait for others to confirm, then I will revert to check the reason it's failing on my end.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Client::get_prune_height

2 participants